package com.lxq.LeetCode.guessNumber;

public class Solution {
    public static int pick = 1702766719;

    public static void main(String[] args) {
        System.out.println(guessNumber(Integer.MAX_VALUE));
    }

    public static int guessNumber(int n) {
        int min = 1, max = n;
        int res = min + (max - min) / 2;
        while (guess(res) != 0) {
            if (guess(res) == -1) {
                max = res - 1;
                res = min + (max - min) / 2;
            } else {
                min = res + 1;
                res = min + (max - min) / 2;
            }
        }
        return res;
    }

    private static int guess(int num) {
        if (pick < num) {
            return -1;
        } else if (pick > num) {
            return 1;
        } else {
            return 0;
        }
    }
}
